import { Component, OnInit } from '@angular/core';
import { SelectItem, TreeNode } from 'primeng/primeng';
import { Router, ActivatedRoute } from '@angular/router';
import { ScheduleService } from './schedule.service';

@Component({
  templateUrl: './schedule.component.html',
  styleUrls: ['./schedule.component.scss'],
  providers: [ScheduleService]
})
export class ScheduleComponent implements OnInit {

  groups: TreeNode[] = [];
  selectedNode: TreeNode;
  constructor(
    private router: Router,
    private scheduleService: ScheduleService) { }

  ngOnInit() {
    this.scheduleService.listGroups().subscribe(data => {
      data.forEach(element => {
        this.groups.push({ 'label': element['systemName'], 'icon': 'fa-folder-open', data: { 'id': element['systemUrl'] } })
        this.selectedNode = this.groups[0];
      });
      this.nodeSelect(null);
    });
  }

  nodeSelect($event) {
    this.router.navigate(['/schedule/list', { "id": this.selectedNode.data['id'] }]);
  }
}